package com.example.chaomi;

import android.util.Log;

public class test {
	
	public class Counter {
		private volatile int count = 0;
		public void inc() {
			try {
				Thread.sleep(1000);
			} catch(Exception e) {
				
			}
			count ++;
		}
		@Override
		public String toString() {
			return "count"+count+"; ";
		}
	}
	public void volatileTest() {
		final Counter counter = new Counter();
		for(int i=0; i<1000; i++) {
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					counter.inc();
				}
			}).start();;
		}
		Log.d("lijh:volatile", "counter:"+counter);
	}
}
